#ifndef ALPHAFIELD_H
#define ALPHAFIELD_H

#include <QWidget>
#include <QPainter>
#include <QSize>
#include <QFont>
#include <QFontMetrics>
#include <stack>
#include "qalphachooser.h"

#include "solver.h"

class QAlphaField : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(QSize fieldSize READ getFieldSize WRITE setFieldSize);
    Q_PROPERTY(QFont font READ font WRITE setFont);
    Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled);
public:
    QAlphaField(QWidget *parent = 0);
    QSize getFieldSize() const;
    void setFieldSize(const QSize &size);
    QSize sizeHint() const;
    void selReset();
    void restartLastConf();
    void fullReset();
    bool isValidWord();
    void setSel(const deque<solver::Coords> &st);

public slots:
    void updateAlpha(QChar c);
    const solver::Field &getField();

signals:
    void stringChanged(QString str);

protected:
    void paintEvent(QPaintEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void updateString();
private:
    enum FieldStatus {afterReset, alphaSet, wordSel};
    FieldStatus status;
    solver::Field f;
    solver::Coords newAlpha;
    int cellSize() const;
    bool checkCoords(int x, int y);
    int chosenX, chosenY;
    QAlphaChooser *ch;
    deque<solver::Coords> sel;
};

#endif // ALPHAFIELD_H
